package com.jamila.scancode.controller;

import com.jamila.scancode.entity.BasicInfo;
import com.jamila.scancode.entity.Contacts;
import com.jamila.scancode.result.Result;
import com.jamila.scancode.service.ContactsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author JAMILA
 * @since 2024-03-30 01:42:05
 */
@Api(tags = "联系人控制器")
@RestController
@RequestMapping("/contacts")
public class ContactsController {
    @Autowired
    private ContactsService contactsService;

    @ApiOperation("保存联系人信息")
    @PostMapping("save")
    public Result save(@RequestBody Contacts contacts){
        //根据手机号判断是否已存在信息；若存在则执行更新操作；若不存在则执行保存操作
        boolean save = contactsService.saveData(contacts);
        return save?Result.ok():Result.fail().message("保存联系人信息失败");
    }

    @ApiOperation("根据手机号查询联系人信息")
    @GetMapping("getContacts/{tel}")
    public Result getContacts(@PathVariable String tel){
        Contacts contacts=contactsService.getContacts(tel);
        return contacts!=null?Result.ok(contacts):Result.ok().message("获取联系人信息失败");
    }

}
